import { URL, DataKey } from '@/config/api.js';
export default {
//上传
  upload: (file, FormData, customUrl='') => {
    const token = uni.getStorageSync(DataKey.token);
    uni.showLoading({
      title: '上传中',
    });
    return new Promise((resolve, reject) => {
      uni.uploadFile({
        url: URL + customUrl,
				fileType: 'image',
        filePath: file,
        name: 'file',
        formData: FormData,
        header: {
          'Content-Type': 'multipart/form-data;boundary=ebf9f03029db4c2799ae16b5428b06bds',
          Authorization: token
        },
        success: (uploadFileRes) => {
					if (uploadFileRes.statusCode == 200) {
						let result = JSON.parse(uploadFileRes.data);
						if (result.code === 0) {
							return resolve(result);
						} else {
						  uni.showToast({
						    icon: 'none',
						    title: result.msg,
						  });
						}
					} else {
						uni.showToast({
						  icon: 'none',
						  title: '文件上传失败',
						});
					}
          
        },
        fail: (error) => {
          console.log('上传失败：', error);
					uni.showToast({
						title: '文件上传失败',
						icon: 'none'
					});
          return resolve(false);
        },
        complete: () => {
          uni.hideLoading();
        },
      });
    });
  },
}